import 'package:flutter/material.dart';
import 'package:x3_base_package/x3_base_package.dart';
import 'package:x3_business_core/business_customer/ful_components/business_customer_details_coupons_tab.dart';

class BusinessCustomerDetailsCoupons extends StatefulWidget {

  static final String sName = 'DepotVipCoupons';

  @override
  _BusinessCustomerDetailsCouponsState createState() => _BusinessCustomerDetailsCouponsState();

}

class _BusinessCustomerDetailsCouponsState extends State<BusinessCustomerDetailsCoupons> {

  BaseTabBarPage _tabPage;

  @override
  Widget build(BuildContext context) {
    dynamic arguments = BaseRouterUtil.getArguments(context);
    String vipId = BaseUtils.getKeyData(arguments, 'vipId').toString();
    return BaseScaffoldComponent(
      title: '优惠券',
      child: _buildMainScaffold(context, vipId),
    );
  }

  Widget _buildMainScaffold(BuildContext context, String vipId) {
    String service = '/x3-service-vip-center/vip/customer/query/runwater/coupontab/total/{vipId}';
    Map<String, dynamic> params = { 'vipId': vipId };
    return BaseScreenRefreshComponent(
      request: new BaseScreenRequestModel(service, method: BaseHttpMethodEnum.GET, params: params ),
      builder: (BaseHttpResultModel result) => _buildTabWidget(context, result.data, vipId),
    );
  }

  Widget _buildTabWidget(BuildContext context, List<dynamic> items, String vipId) {
    String service = '/x3-service-vip-center/vip/customer/query/runwater/coupontab';
    List<BaseTabConfig> tabs = items.map((dynamic item) {
      String stateName = BaseUtils.getKeyData(item, 'stateName').toString();
      String total = BaseUtils.getKeyData(item, 'total').toString();
      String state = BaseUtils.getKeyData(item, 'state').toString();
      return BaseTabConfig(text: '$stateName($total)', child: BusinessCustomerDetailsCouponsTab(vipId: vipId, couponState: state, inputApi: service));
    }).toList();
    this._tabPage = BaseTabBarPage(tabs);
    return Column(children: [this._tabPage.buildTabBar(context), Expanded(child: this._tabPage.buildTabView())]);
  }

  @override
  void dispose() {
    _tabPage?.dispose();
    super.dispose();
  }

}
